from pydantic import BaseModel
from typing import Optional
from datetime import datetime

# 附件基础模型
class AttachmentBase(BaseModel):
    filename: str
    original_filename: str
    file_size: Optional[int] = None
    mime_type: Optional[str] = None

# 附件创建模型
class AttachmentCreate(AttachmentBase):
    file_path: str
    entity_type: str
    entity_id: int

# 附件响应模型
class AttachmentResponse(AttachmentBase):
    id: int
    file_path: str
    entity_type: str
    entity_id: int
    uploaded_by: int
    created_at: datetime
    updated_at: datetime
    
    # 计算属性：文件URL
    @property
    def file_url(self) -> str:
        return f"/api/attachments/{self.id}/download"

    class Config:
        orm_mode = True

# 附件上传模型
class AttachmentUpload(BaseModel):
    entity_type: str
    entity_id: int